package com.springbootdatajpa.controller;

import com.springbootdatajpa.entity.User;
import com.springbootdatajpa.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {

    @Autowired
    private UserRepository userRepository;

    @RequestMapping("/select")
    public User selectById(){
        List<User> user = userRepository.findAll();
        return user.get(0);
    }

    @RequestMapping("/save")
    public User insertUser(){
        User userTest = new User();
        userTest.setId(1);
        userTest.setName("千晨");
        userTest.setEmail("123@qq.com");
        User user = userRepository.save(userTest);
        return user;
    }
}
